
import { _decorator, Component, Node ,Canvas} from 'cc';
const { ccclass, property } = _decorator;

/**
 * Predefined variables
 * Name = timecont
 * DateTime = Wed Apr 13 2022 13:26:45 GMT+0800 (中国标准时间)
 * Author = xiaopang125
 * FileBasename = timecont.ts
 * FileBasenameNoExtension = timecont
 * URL = db://assets/timecont.ts
 * ManualUrl = https://docs.cocos.com/creator/3.4/manual/zh/
 *
 */
 
@ccclass('timecont')
export class timecont extends Component {
    // [1]
    // dummy = '';
    count =60;
    private label: any = null

    @property({ type: Canvas })
    private stage = null;

    start () {
        // [3]
    
    }
    public timestart(){
        this.count =60;

        this.label = this.getComponent(cc.Label);
        this.schedule(function() {
            // 这里的 this 指向 component
            // this.doSomething();
            // console.log(this);
            this.count--;

           
            let text = this.count + '';
            // Change the text in Label Component
            this.label.string = text;
            if(this.count<=0){
         this.timeend();
            }
        }, 0.1,59);
    
    }

    private timeend(){
        console.log('倒计时结束');
        this.label.string ='本次积分';
        this.stage.node.getChildByName("StartBtn").active=true;
        this.stage.node.getChildByName("StartBtn").getChildByName("Label").getComponent(cc.Label).string ='继续挑战';
        console.log(this.stage.node.getChildByName("StartBtn").getChildByName("Label"));
        
        this.stage.getComponent('gameclick').enabled =false;
        this.stage.getComponent('gameclick').node.pauseSystemEvents();


    }

    // update (deltaTime: number) {
    //     // [4]
    // }
}

/**
 * [1] Class member could be defined like this.
 * [2] Use `property` decorator if your want the member to be serializable.
 * [3] Your initialization goes here.
 * [4] Your update function goes here.
 *
 * Learn more about scripting: https://docs.cocos.com/creator/3.4/manual/zh/scripting/
 * Learn more about CCClass: https://docs.cocos.com/creator/3.4/manual/zh/scripting/decorator.html
 * Learn more about life-cycle callbacks: https://docs.cocos.com/creator/3.4/manual/zh/scripting/life-cycle-callbacks.html
 */
